﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.BaseInformation;


namespace TyMES.ViewModel.BaseInformation.CodeTypeVMs
{
    public partial class CodeTypeListVM : BasePagedListVM<CodeType_View, CodeTypeSearcher>
    {

        protected override IEnumerable<IGridColumn<CodeType_View>> InitGridHeader()
        {
            return new List<GridColumn<CodeType_View>>{
                this.MakeGridHeader(x => x.CodeName),
                this.MakeGridHeader(x => x.CodeDescribe),
                this.MakeGridHeader(x => x.CodeRegex),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<CodeType_View> GetSearchQuery()
        {
            var query = DC.Set<CodeType>()
                .CheckContain(Searcher.CodeName, x=>x.CodeName)
                .CheckContain(Searcher.CodeDescribe, x=>x.CodeDescribe)
                .CheckContain(Searcher.CodeRegex, x=>x.CodeRegex)
                .Select(x => new CodeType_View
                {
				    ID = x.ID,
                    CodeName = x.CodeName,
                    CodeDescribe = x.CodeDescribe,
                    CodeRegex = x.CodeRegex,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class CodeType_View : CodeType{

    }
}
